import bz2

file = "1_bz2_压缩字节流.py"
data = ""
with open(file, "rb") as f:
    data = f.read()

# 压缩
with bz2.open(file + ".bz2", "wb") as out_fp:
    # shutil.copyfileobj(f, out_fp)
    out_fp.write(data)

# 解压
with bz2.open(file + ".bz2", "rb") as in_fp:
    decompress_data = in_fp.read()

# 对比
print("bz2 压缩,解压对比结果:", data == decompress_data)
